// import Vue from 'vue'
// import Vuex from 'vuex'

// Vue.use(Vuex)

// #ifdef VUE3
import { createStore } from 'vuex'
import { Dict } from '../components/custom_views/dict'
import { post } from '../api/cust_request'

const defaultAvatar = "https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0"
// import { defaultPostSellDto, getDefaultPostDto } from '../pages/post_add_sell/post_add_sell_dto'
import { defaultPostSellDto, getDefaultPostDto } from "@/components/post_item/post_add_sell_dto";
import { CustomDate } from '../components/custom_views/custom_date'
import { defaultCustomModal, showCustomModalMixin } from '../components/custom_views/show-custom-modal-mixin'
import { defaultCustomTips } from '../components/custom_views/show-custom-tips-mixin'
// import { vueVersion } from '../TUIKit/adapter-vue'
const store = createStore({
	// #endif
	state: {
		// 默认的session信息
		sessionDto: {
			// 用户信息
			userDto: {
				userId: null,
				openid: null,
				unionid: null,
				mobile: null,
				avatarUrl: defaultAvatar,
				nickName: '未知',
				gender: 0,
				birth: null,
				pointCount: 0,
				pointNumber: 0,
				growthNumber: 0,
			},
			// 指标信息，收藏数、分享数等
			metricRecordDtoMap: {
				collectNumber: 0,
				shareNumber: 0,
				viewNumber: 0,
				postNumber: 0,
				postBuyNumber: 0,
			},
			// 未读回复数
			unreadCommentNumber:0,
			// 是否首次登录
			firstLogin: Dict.YesEnum.Yes.value
		},
		// import { TUIChatKit, genTestUserSig } from "./TUIKit";
		// import { vueVersion } from "./TUIKit/adapter-vue";
		// import { TUILogin } from "@tencentcloud/tui-core";
		imSession: {
			hasLogin: false,
		},
		// 我发布的帖子
		myPostList: [],
		// 当前选定的城市信息，目前只有背景
		currentRegion: {
			provinceCode: '11',
			province: '北京市',
			cityCode: '1101',
			city: '北京市',
		},
		myPostOfEditingSell: getDefaultPostDto(Dict.PostMainTypeEnum.Shop.childs.ShopSell.value),
		showCustomModal:{
			show: false,
			title: '',
			content: '',
			confirmText: '确定',
			cancelText: '取消',
			cancelColor: 'rgba(0, 0, 0, 0.85)',
			confirmColor: '#666666',
			success: null
		},
		showCustomTips:{
			show: false,
			title: '',
			content: '',
			confirmText: '确定',
			cancelText: '取消',
			cancelColor: 'rgba(0, 0, 0, 0.85)',
			confirmColor: '#666666',
			success: null
		}
	},
	mutations: {
		// 登录
		login(state, [userId, userInfo]) {
			// 持久化登录的用户id和用户信息
		},
		// 退出
		logout(state) {
			// 清空登录信息
			// uni.clearStorageSync()
			uni.removeStorageSync('userId')
			uni.removeStorageSync('userInfo')
		},
		updateSessionDto(state, sessionDto){
			state.sessionDto = sessionDto
		},
		updateUnreadCommentNumber(state, unreadCommentNumber){
			state.sessionDto['unreadMsgNumber'] = unreadCommentNumber
		},
		updateImSession(state, imSession){
			state.imSession = imSession
		},
		imLogin(state, result){
			state.imSession.hasLogin = result
		},
		imLogout(state){
			
		},
		updateMyPostList(state, myPostList){
			state.myPostList = myPostList
		},
		changeUserId(state, userId){
			console.log('改变userId:', userId)
			state.userInfo.userId = userId
		},
		updateMyPostOfEditingSell(state, postDto){
			state.myPostOfEditingSell = postDto
		},
		updateShowCustomModal(state, showCustomModal){
			state.showCustomModal = showCustomModal
		},
		successShowCustomModal(state, res){
			if(res == 'confirm'){
				state.showCustomModal.success({
					confirm: true,
					cancel: false
				})

			}else if(res == 'cancel'){
				console.log('用户点击了取消', defaultCustomModal)
				state.showCustomModal.success({
					cancel: true,
					confirm: false
				})
				state.showCustomModal = Object.assign({},defaultCustomModal)
				state.showCustomModal.show = false
			}
		},
		hideShowCustomModal(state){
			state.showCustomModal.show = false
		},

		updateShowCustomTips(state, showCustomTips){
			state.showCustomTips = showCustomTips
		},
		successShowCustomTips(state, res){
			if(res == 'confirm'){
				state.showCustomTips.success({
					confirm: true,
					cancel: false
				})
				state.showCustomTips = Object.assign({}, defaultCustomTips)
				state.showCustomTips.show = false

			}else if(res == 'cancel'){
				state.showCustomTips.success({
					cancel: true,
					confirm: false
				})
				state.showCustomTips = Object.assign({}, defaultCustomTips)
				state.showCustomTips.show = false
			}
		},
	},
	getters: {
		myPostListOfBuy(state, getters){
			return state.myPostList.filter(post => post.postType == Dict.PostMainTypeEnum.Shop.childs.ShopBuy.value)
		},
		myPostListOfSell(state, getters){
			return state.myPostList.filter(post => post.postType == Dict.PostMainTypeEnum.Shop.childs.ShopSell.value)
		},
		// 获得userId
		getUserId(state, getters) {
		},
		// 获得用户信息
		getUserInfo(state, getters) {
		},
		getAddressInfo(state, getters) {
		},
		getJoinDays(state, getters){
			if(state.sessionDto.userDto && state.sessionDto.userDto.createTime){
				return CustomDate.calDaysFromDate(state.sessionDto.userDto.createTime)
			}else{
				return 1
			}
		}

	},
})

export default store
